﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Alti.SharePoint.SPDataGenerator.Models;
using Microsoft.SharePoint;

namespace Alti.SharePoint.SPDataGenerator.Presenters
{
    public static class SharePointService
    {

        public static List<SPDataContentType> GetContentTypes(string WebUrl)
        {
            List<SPDataContentType> contentTypes = new List<SPDataContentType>();

            using (SPSite aSite = new SPSite(WebUrl))
            {
                using (SPWeb aWeb = aSite.OpenWeb())
                {
                    foreach (SPContentType ct in aWeb.ContentTypes)
                    {
                        contentTypes.Add(Converters.SPContentTypeToSPDataContentType(ct));
                    }
                }
            }
            return contentTypes;
        }



        public static List<SPDataList> GetLists(string WebUrl)
        {
            List<SPDataList> lists = new List<SPDataList>();
            using (SPSite aSite = new SPSite(WebUrl))
            {
                using (SPWeb aWeb = aSite.OpenWeb())
                {
                    foreach (SPList list in aWeb.Lists)
                    {
                        lists.Add(Converters.SPListToSPDataList(list));
                    }
                }
            }
            return lists;
        }


    }
}
